<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图片上传</title>
</head>
<body>
    <input type="file" class="upload">
    <img src="" alt="" class="my-img">
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.2.0/axios.min.js"></script>
    <script>
        document.querySelector('.upload').addEventListener('change',e=>{
            const fd=new FormData()
            fd.append('img',e.target.files[0])
            axios({
                url:'http://hmajax.itheima.net/api/uploadimg',
                method:'POST',
                data:fd //multipart/form-data

            }).then(result=>{
                const imgUrl=result.data.data.url
                document.querySelector('.my-img').src=imgUrl
            })

        })
    </script>
</body>
</html>